<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<div id=editor contenteditable></div>
<script>
    shouldBeTrue("document.queryCommandEnabled('DefaultParagraphSeparator')");
    shouldBeEqualToString("document.queryCommandValue('DefaultParagraphSeparator')", "div"); // Default is div.
    evalAndLog("document.execCommand('DefaultParagraphSeparator', false, 'p')");
    shouldBeEqualToString("document.queryCommandValue('DefaultParagraphSeparator')", "p");
    evalAndLog("document.execCommand('DefaultParagraphSeparator', false, 'br')");
    shouldBeEqualToString("document.queryCommandValue('DefaultParagraphSeparator')", "p");
    evalAndLog("document.execCommand('DefaultParagraphSeparator', false, 'invalid')");
    shouldBeEqualToString("document.queryCommandValue('DefaultParagraphSeparator')", "p");

    debug("\nCreating paragraphs in the normal way.");
    var div = document.querySelector("#editor");
    div.focus();
    evalAndLog("document.execCommand('InsertText', false, 'a')");
    shouldBeEqualToString("div.innerHTML", "a");
    evalAndLog("document.execCommand('InsertText', false, '\\n')");
    shouldBeEqualToString("div.innerHTML", "a<p><br></p>");
    evalAndLog("document.execCommand('InsertText', false, 'b')");
    shouldBeEqualToString("div.innerHTML", "a<p>b</p>");
    evalAndLog("document.execCommand('InsertText', false, '\\n')");
    shouldBeEqualToString("div.innerHTML", "a<p>b</p><p><br></p>");
    evalAndLog("document.execCommand('Delete')");
    shouldBeEqualToString("div.innerHTML", "a<p>b</p>");
    evalAndLog("document.execCommand('Delete')");
    shouldBeEqualToString("div.innerHTML", "a<p><br></p>");
    evalAndLog("document.execCommand('Delete')");
    shouldBeEqualToString("div.innerHTML", "a");
    evalAndLog("document.execCommand('DefaultParagraphSeparator', false, 'div')");
    evalAndLog("document.execCommand('InsertParagraph')");
    shouldBeEqualToString("div.innerHTML", "a<div><br></div>");
    evalAndLog("div.innerHTML = ''");

    debug("\nUsing the previous block as template for the new one.");
    evalAndLog("document.execCommand('DefaultParagraphSeparator', false, 'p')");
    debug('document.execCommand("InsertHTML", false, "&lt;pre&gt;a&lt;/pre&gt;");');
    document.execCommand("InsertHTML", false, "<pre>a</pre>");
    shouldBeEqualToString("div.innerHTML", "<pre>a</pre>");
    evalAndLog("document.execCommand('InsertText', false, 'b')");
    shouldBeEqualToString("div.innerHTML", "<pre>ab</pre>");
    evalAndLog("document.execCommand('InsertText', false, '\\n')");
    shouldBeEqualToString("div.innerHTML", "<pre>ab</pre><pre><br></pre>");
    evalAndLog("document.execCommand('InsertText', false, 'c')");
    shouldBeEqualToString("div.innerHTML", "<pre>ab</pre><pre>c</pre>");
    evalAndLog("document.execCommand('DefaultParagraphSeparator', false, 'div')");
    evalAndLog("document.execCommand('InsertText', false, '\\n')");
    shouldBeEqualToString("div.innerHTML", "<pre>ab</pre><pre>c</pre><pre><br></pre>");
    evalAndLog("document.execCommand('Delete')");
    evalAndLog("document.execCommand('InsertParagraph')");
    shouldBeEqualToString("div.innerHTML", "<pre>ab</pre><pre>c</pre><pre><br></pre>");

    debug("\nBreaking out of lists.");
    evalAndLog("div.innerHTML = ''");
    evalAndLog("document.execCommand('DefaultParagraphSeparator', false, 'p')");
    debug('document.execCommand("InsertHTML", false, "&lt;ul>&lt;li>a&lt;/li>&lt;/ul>")');
    document.execCommand("InsertHTML", false, "<ul><li>a</li></ul>");
    shouldBeEqualToString("div.innerHTML", "<ul><li>a</li></ul>");
    evalAndLog("document.execCommand('InsertParagraph')");
    evalAndLog("document.execCommand('InsertParagraph')");
    shouldBeEqualToString("div.innerHTML", "<ul><li>a</li></ul><p><br></p>");

    debug("\nBreaking up nested elements.");
    evalAndLog("div.innerHTML = ''");
    debug('document.execCommand("InsertHTML", false, "&lt;cite>a&lt;cite>bc&lt;/cite>&lt;/cite>")');
    document.execCommand("InsertHTML", false, "<cite>a<cite>bc</cite></cite>");
    evalAndLog('window.getSelection().modify("move", "backward", "character")');
    evalAndLog("document.execCommand('InsertParagraph')");
    shouldBeEqualToString("div.innerHTML", "<cite>a<cite>b</cite></cite><p><cite><cite>c</cite></cite></p>");

    div.innerHTML = "";
</script>
</body>
</html>
